var add = document.getElementById("add");
var revise = document.getElementById("revise");
var adddiv = document.getElementById("adddiv");
var finddiv = document.getElementById("finddiv");
var record = document.getElementsByClassName("record")[0];
var revisediv = document.getElementById("revisediv");
add.onclick = function () {
    adddiv.classList.remove("top");
    adddiv.classList.add("down");
    adddiv.style.top = "20vh";
}
// 1
var fade = document.getElementsByClassName("fade");
fade[0].onclick = function () {
    adddiv.classList.remove("down");
    adddiv.classList.add("top");
    adddiv.style.top = "-350px";
}
revise.onclick = function () {
    revisediv.classList.remove("top");
    revisediv.classList.add("down");
    revisediv.style.top = "20vh";
}
fade[1].onclick = function () {
    revisediv.classList.remove("down");
    revisediv.classList.add("top");
    revisediv.style.top = "-350px";
}
fade[2].onclick = function () {
    finddiv.classList.remove("down");
    finddiv.classList.add("top");
    finddiv.style.top = "-350px";
}
var del = document.getElementsByClassName("delete");
function dele() {
    for (var i = 0; i < del.length; i++) {
        del[i].onclick = function () {
            var tr = this.parentNode.parentNode;
            var name = tr.getElementsByTagName("td")[1].innerHTML;
            var choose = confirm("你是否确定删除" + name + "的信息?");
            if (choose == true) {
                tr.parentNode.removeChild(tr);
            }
        }
    }
}
dele();
function addp() {
    var addinput = document.getElementsByClassName("addinput");
    var tr = document.getElementsByTagName("tr");
    var addlink = addinput[0].value;
    var boo = true;
    var boon = true;
    for (let n = 0; n < addinput.length; n++) {
        if (addinput[n].value == "") { alert("请输入完整信息!"); boon = false; break; }
    }
    for (let i = 1; i < tr.length; i++) {
        var link = tr[i].getElementsByTagName("td")[0].innerHTML;
        if (addlink == link) { alert("您要添加的序号已存在!"); boo = false; }
    }
    if (boo && boon) {
        record.innerHTML += "<tr>" +
            "<td>" + addinput[0].value + "</td>" +
            "<td>" + addinput[1].value + "</td>" +
            "<td>" + addinput[2].value + "</td>" +
            "<td>" + addinput[3].value + "</td>" +
            "<td>" + addinput[4].value + "</td>" +
            "<td><a class='delete' href='javascript:;'>删除信息</a></td>" +
            "</tr>";
    }
    dele();
}
function revisep() {
    var reviseinput = document.getElementsByClassName("reviseinput");
    var tr = document.getElementsByTagName("tr");
    var inputlink = reviseinput[0].value;
    var boo = true;
    var boon = true;
    for (let n = 0; n < reviseinput.length; n++) {
        if (reviseinput[n].value == "") { alert("请输入完整信息!"); boon = false; break; }
    }
    for (let i = 1; i < tr.length; i++) {
        var link = tr[i].getElementsByTagName("td")[0].innerHTML;
        if (inputlink == link && boon) {
            tr[i].getElementsByTagName("td")[1].innerHTML = reviseinput[1].value;
            tr[i].getElementsByTagName("td")[2].innerHTML = reviseinput[2].value;
            tr[i].getElementsByTagName("td")[3].innerHTML = reviseinput[3].value;
            tr[i].getElementsByTagName("td")[4].innerHTML = reviseinput[4].value;
            boo = false;
        }
    }
    // var link=tr[1].getElementsByTagName("td")[0].innerHTML;
    if (boo && boon) { alert("您输入的序号不存在"); }
    dele();
}
function autointo(){
    var reviseinput = document.getElementsByClassName("reviseinput");
    var tr = document.getElementsByTagName("tr");
    for (let i = 1; i < tr.length; i++) {
        var link = tr[i].getElementsByTagName("td")[0].innerHTML;
        if(link==reviseinput[0].value){
            reviseinput[1].value=tr[i].getElementsByTagName("td")[1].innerHTML;
            reviseinput[2].value=tr[i].getElementsByTagName("td")[2].innerHTML;
            reviseinput[3].value=tr[i].getElementsByTagName("td")[3].innerHTML;
            reviseinput[4].value=tr[i].getElementsByTagName("td")[4].innerHTML;
        }
    }
}
function find(){
    var boo = false;
    var tr = document.getElementsByTagName("tr");
    var findtext = document.getElementsByClassName("findtext");
    var findinput=document.getElementsByClassName("findinput")[0].value;
    for (let i = 1; i < tr.length; i++) {
        var link = tr[i].getElementsByTagName("td")[0].innerHTML;
        if(link==findinput){
            boo=true;
            findtext[0].innerHTML=tr[i].getElementsByTagName("td")[0].innerHTML;
            findtext[1].innerHTML=tr[i].getElementsByTagName("td")[1].innerHTML;
            findtext[2].innerHTML=tr[i].getElementsByTagName("td")[2].innerHTML;
            findtext[3].innerHTML=tr[i].getElementsByTagName("td")[3].innerHTML;
            findtext[4].innerHTML=tr[i].getElementsByTagName("td")[4].innerHTML;
        }
    }
    if(boo){
    finddiv.classList.remove("top");
    finddiv.classList.add("down");
    finddiv.style.top = "20vh";
    }
    else{alert("请输入正确的序号!");}
}